package pl.textureStudio.view.panel.base
{
	import pl.error.InternalError;
	import pl.textureStudio.view.panel.WelcomePanel;
	import pl.textureStudio.view.panel.create.CreateTexturePanel;
	import pl.textureStudio.view.panel.edit.TextureEditPanel;

	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Point;

	/**
	 * @author michalr
	 */
	public class BasePanel extends Sprite implements IBasePanel
	{
		private var _size:Point;
		private var _panelID:String;

		public function BasePanel()
		{
			addEventListener( Event.ADDED_TO_STAGE, onATS );
		}

		private function onATS( event:Event ):void
		{
			removeEventListener( Event.ADDED_TO_STAGE, onATS );
			init();
		}

		protected function init():void
		{
		}

		public static function factory( panelID:String ):IBasePanel
		{
			var vo:BasePanel;
			if (panelID == PanelType.EDIT)
			{
				vo = new TextureEditPanel();
				vo._size = new Point( 500, 450 );
				vo._panelID = panelID;
			}
			if (panelID == PanelType.WELCOME)
			{
				vo = new WelcomePanel();
				vo._size = new Point( 900, 450 );
				vo._panelID = panelID;
			}

			if (panelID == PanelType.CREATE_NEW)
			{
				vo = new CreateTexturePanel();
				vo._size = new Point( 900, 450 );
				vo._panelID = panelID;
			}
			if (vo != null) vo.realign();

			return 	vo;
		}

		protected function realign():void
		{
			x = Math.floor( -size.x * .5 );
			y = Math.floor( -size.y * .5 );
		}

		public function destroy():void
		{
		}

		public function hide():void
		{
			throw new Error( InternalError.OVERRIDE_ERROR );
		}

		public function get panelID():String
		{
			return _panelID;
		}

		public function get size():Point
		{
			return _size;
		}

		public function set size( val:Point ):void
		{
			_size = val;
		}
	}
}
